package com.example.demo.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.example.demo.controller.bean.Result;
import com.example.demo.dto.AdoptCheckinDTO;
import com.example.demo.dto.CheckinRequestDTO;
import com.example.demo.dto.RejectCheckinDTO;
import com.example.demo.service.CheckinAuditorService;
import com.example.demo.utils.PageBo;
import com.example.demo.utils.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Lucy
 * @create 2024-03-15 13:58
 */
@Api("拍照打卡审核接口")
@RequestMapping("checkinAuditor")
@RestController
@Slf4j
public class CheckinAuditorController {

    @Autowired
    private CheckinAuditorService service;

    @ResponseBody
    @ApiOperation("获取待审核的拍照打卡列表")
    @RequestMapping(value = "getCheckinList")
    public Result<PageVo<CheckinRequestDTO>> getCheckinList(@RequestBody PageBo pageBo) {
        PageVo<CheckinRequestDTO> list = service.getCheckinList(pageBo);
        return Result.ok(list);
    }

    @RequestMapping(value ="adopt", method = {RequestMethod.POST})
    @ApiOperation(value = "批准打卡", notes = "开发中")
    public Result<String> adoptCheckin (@RequestBody AdoptCheckinDTO dto){
        int userId = StpUtil.getLoginIdAsInt();
        service.updateCheckinStatus(dto.getImageId(), 2, 1);
        service.updateCompletionStatus(dto.getId(),2,1,userId);
        return Result.ok("操作成功");
    }

    @RequestMapping(value = "reject", method = {RequestMethod.POST})
    @ApiOperation(value = "拒绝打卡", notes = "开发中")
    public Result<String> rejectCheckin (@RequestBody RejectCheckinDTO dto){
        int userId = StpUtil.getLoginIdAsInt();
        service.updateCheckinStatus(dto.getImageId(), 2, 2);
        service.updateCompletionStatus(dto.getId(),4,2,userId);
        service.updateReviewerComments(dto.getId(), dto.getReviewComments());
        return Result.ok("操作成功");
    }
}
